package wb.is.besti.edu.cd.javalibgame;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Mr.Z on 2017/12/17.
 */

public class GradeAdapter extends ArrayAdapter<Grade>{

    private int resourceId;

    public GradeAdapter(Context context, int textViewResourceId, List<Grade> objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        Grade grade = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
        ImageView gradeImage = (ImageView)view.findViewById(R.id.grade_image);
        TextView gradeName = (TextView)view.findViewById(R.id.grade_name);
        if (grade.getImageId()!=0){
            gradeImage.setImageResource(grade.getImageId());
        }
        gradeName.setText(grade.getName());
        return view;
    }
}
